# -*- coding = utf-8 -*-
# @Time :2024/1/31 10:29
# @Author :invictusQAQ
# @Description :
# @File :  login_page.py
from time import sleep
from selenium.webdriver.common.by import By
from config.config import login_url
from base.base_page import BasePage
import allure


class LoginPage(BasePage):
    username = (By.XPATH, '//*[@id="app"]/div/div/div[1]/label[1]/input')
    password = (By.XPATH, '//*[@id="app"]/div/div/div[1]/label[2]/input')
    login_button = (By.XPATH, '//*[@id="app"]/div/div/div[1]/button')
    logout_loc = (By.CSS_SELECTOR, '.pan-user-info.el-tooltip__trigger.el-tooltip__trigger')
    logout_button = (By.XPATH, '//*[@class="el-dropdown-menu"]/li[2]')
    confirm_quit = (By.XPATH, '/html/body/div[22]/div/div/div[3]/button[2]')

    @allure.step('登录')
    def login(self, user, pwd):
        self.visit(login_url)
        self.input(self.username, user)
        self.input(self.password, pwd)
        self.click(self.login_button)

    def logout(self):
        sleep(3)
        self.click(self.logout_loc)
        sleep(1)
        self.click(self.logout_button)
        sleep(2)
        self.click(self.confirm_quit)

    def clear_input(self):
        self.clear(self.username)
        self.clear(self.password)
